<template>
  <div>
    <SearchFrame @search="searchResult" tip="职业技能"/>
    <div class="selectBar2">
      <div>
        <el-select
          v-model.trim="education"
          placeholder="学历要求"
          size="small"
          style="width: 126px"
          @change="changeEducation">
          <el-option
            v-for="item in educationOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"></el-option>
        </el-select>
        <el-select
          v-model.trim="status"
          placeholder="申请状态"
          size="small"
          style="width: 126px"
          @change="changeApplyStatus">
          <el-option
            v-for="item in statusOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"></el-option>
        </el-select>
      </div>
      <div class="clearBtn" @click="clearSelect">清空筛选条件</div>
    </div>
    <ContainerTitle text="我申请的简历列表" class="title"></ContainerTitle>
    <div class="msgDiv">
      <el-table
        :data="myApplys"
        style="width: 100%; margin-bottom: 30px"
        border
        min-height="500"
        :header-cell-style="{ background: '#f4f4f4', color: '#666' }">
        <el-table-column
          prop="workerName"
          label="姓名"
          :resizable="false"
        ></el-table-column>
        <el-table-column prop="genderName" label="性别"></el-table-column>
        <el-table-column
          prop="educationName"
          label="学历"
        ></el-table-column>
        <el-table-column
          prop="age"
          label="年龄"
        ></el-table-column>
        <el-table-column
          prop="createTime"
          label="申请时间"
          width="160"
        ></el-table-column>
        <el-table-column
          prop="skill"
          label="职业技能"
          min-width="100"
        ></el-table-column>
        <el-table-column prop="status" label="申请状态">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 1" style="color: #666">待通过</span>
            <span
              v-if="
              scope.row.status == 2 && !scope.row.offerStatus || 
              scope.row.status == 2 && scope.row.offerStatus == 1 ||
              scope.row.status == 2 && scope.row.offerStatus == 2"
              style="color: #10a217">已通过</span>
            <span v-if="scope.row.status == 3" style="color: #dc6767">未通过</span>
            <!-- <span
              v-if="scope.row.status == 2 && scope.row.offerStatus == 1"
              style="color: #10a217">已录取</span>
            <span
              v-if="scope.row.status == 2 && scope.row.offerStatus == 2"
              style="color: #dc6767">已拒绝</span> -->
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <span class="rowBtn" @click="toDetail(scope.row)">查看</span>
            <span
              class="rowBtn"
              @click="resumePass(scope.row)"
              v-if="scope.row.status == 2 && !scope.row.offerStatus">录用</span>
            <span
              class="rowBtn"
              @click="resumeReject(scope.row)"
              v-if="scope.row.status == 2 && !scope.row.offerStatus">拒绝</span>
          </template>
        </el-table-column>
      </el-table>
      <div id="Pagination" v-show="myApplys.length > 0">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageSize"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import SearchFrame from "@/views/help/components/searchFrame";

import { checkLogin } from "@/utils/util.js";
import { getEducationSelectList, getMyApply, Pass, Reject } from "@/common/api/company.js";

export default {
  name: "companyMyResume",
  components: { SearchFrame },
  data() {
    return {
      myApplys: [],
      crumbs: [
        {label: "企业空间",value: "company",},
        {label: "人才服务",value: "help",},
        {label: "我申请的简历",value: "companyMyResume",choose: true,},
      ],
      pageNum: 1,
      pageSize: 10,
      skill: '',
      education: '',
      status: '',
      total: null,
      educationOptions: [],
      statusOptions: [
        {dictLabel: "待通过",dictValue: "1"},
        {dictLabel: "未通过",dictValue: "3"},
        {dictLabel: "已通过",dictValue: "2"}
      ]
    };
  },
  methods: {
    // 搜索结果
    searchResult(res) {
      this.skill = res
      this.getMyApply()
    },
    // 获取学历要求下拉列表
    async getEducationSelectList() {
      const { code, msg, data } = await getEducationSelectList();
      if (code != "200") return this.$message.warning(msg);
      this.educationOptions = data.worker_education;
    },
    // 下拉改变学历
    changeEducation(val) {
      this.education = val;
      this.getMyApply()
    },
    // 下拉改变状态
    changeApplyStatus(val) {
      this.status = val;
      this.getMyApply()
    },
    // 清空筛选条件 - 学历不限置空
    clearSelect() {
      this.education = "";
      this.status = "";
      this.getMyApply()
    },
    // 获取我申请的简历
    async getMyApply() {
      let params = { 
        pageNum: this.pageNum, 
        pageSize: this.pageSize,
        education: this.education != 0 ? this.education : "",
        skill: this.skill,
        status: this.status
      };
      const { code, msg, rows, total } = await getMyApply(params);
      if (code != "200") return this.$message.warning(msg);
      this.myApplys = rows;
      this.total = total;
    },
    //跳转我申请的简历列表详情
    toDetail(row) {
      this.$router.push({
        path: "companyMyResumeDetail",
        query: { id: row.id, status: row.status },
      });
    },
    /**
     * 确认录用
     */
    resumePass(row) {
      this.$confirm("是否录用该人员为公司员工？")
        .then((res) => {
          this.Pass(row);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    /**
     * 录用
     */
    async Pass(row) {
      let { code, msg } = await Pass({ id: row.id });
      if (code != 200) {
        return this.$message.error(msg);
      }
      this.$message.success("操作成功");
      this.getMyApply();
    },
    /**
     * 确认拒绝
     */
    resumeReject(row) {
      this.$confirm("您确定拒绝该人员不为公司员工？")
        .then((res) => {
          this.Reject(row);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    /**
     * 拒绝
     */
    async Reject(row) {
      let { code, msg } = await Reject({ id: row.id });
      if (code != 200) {
        return this.$message.error(msg);
      }
      this.$message.success("操作成功");
      this.getMyApply();
    },
    // 改变每页大小
    handleSizeChange(e) {
      this.pageSize = e;
      this.getMyApply();
    },
    // 改变当前页
    handleCurrentChange(e) {
      this.pageNum = e;
      this.getMyApply();
    },
  },
  mounted() {
    if(checkLogin(this)){
      this.getEducationSelectList()
      this.getMyApply()
    }
  },
  activated() {
    if(checkLogin(this)){
      this.getEducationSelectList()
      this.getMyApply()
    }
  },
};
</script>

<style lang="scss" scoped>
.selectBar2 {
  width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .el-select {
    margin-right: 10px;
  }
  .clearBtn {
    width: 120px;
    height: 32px;
    line-height: 32px;
    background-color: #ffffff;
    // padding: 5px 15px;
    font-size: 13px;
    border-radius: 3px;
    transition: all 0.2s ease 0s;
    border: 1px solid #eeeeee;
    color: #606266;
    margin-left: 20px;
  }
  .clearBtn:hover {
    cursor: pointer;
    box-shadow: 0px 0px 5px #eeeeee;
  }
}

.msgDiv {
  margin: 20px 0;
  width: 100%;
}

::v-deep .el-table tbody tr:hover > td {
  background-color: #ffffff !important;
}

::v-deep .el-table--border::after,
.el-table--group::after {
  width: 0;
}

::v-deep .el-table--border th.gutter:last-of-type {
  border: none;
}

::v-deep .el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #eeeeee;
}

::v-deep .is-leaf {
  font-weight: normal;
}

::v-deep .el-table td,
.el-table th {
  padding: 10px 0;
}

.rowBtn {
  text-decoration: underline;
  color: #045db9;
}

.rowBtn:hover {
  cursor: pointer;
}

#Pagination {
  display: flex;
  justify-content: flex-end;
}
</style>